package leetcode_2301_2400;

public class LeeCode_2375 {
    public static void main(String[] args) {
//        System.out.println(smallestNumber("IIIDIDDD"));
//        System.out.println(smallestNumber("DDD"));
//        System.out.println(smallestNumber("DDD"));
        System.out.println(smallestNumber("IDDIIDD"));
    }
    private static String smallestNumber(String pattern) {
        int n = pattern.length(), i = 0;
        char cur = '1';
        char[] ans = new char[n + 1];
        while (i < n){
            if (i > 0 && pattern.charAt(i) == 'I')
                i++;
            for(; i < n && pattern.charAt(i) == 'I'; i++){
                ans[i] = cur++;
            }
            int i0 = i;
            for(; i < n && pattern.charAt(i) == 'D'; i++){}
            for (int j = i; j >= i0; j--){
                ans[j] = cur++;
            }
        }
        return new String(ans);
    }
}
